﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Controls.Controls;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.IO;
using System.Windows;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{ 
    public class MainViewModel : ViewModelBase
    { 
       
        public SETINTEXDB SetEnv
        {
            get;
            set;

        }
        public SETINTEXDB SetProd
        {
            get;
            set;
        }
        public SETINTEXDB SetData
        {
            get;
            set;
        }
        public bool IsMaster
        {
            get
            {
                return app.IsMaster;
            }
        } 
        private string _ABFAGANG; public string ABFAGANG { get { return _ABFAGANG; } set { _ABFAGANG = value; OnPropertyChanged("ABFAGANG"); } }
        private string _KRS; public string KRS { get { return _KRS; } set { _KRS = value; OnPropertyChanged("KRS"); } }
        private string _LFD; public string LFD { get { return _LFD; } set { _LFD = value; OnPropertyChanged("LFD"); } }
        private string _POS; public string POS { get { return _POS; } set { _POS = value; OnPropertyChanged("POS"); } }
         
        private string _SPINLOT; public string SPINLOT { get { return _SPINLOT; } set { _SPINLOT = value; OnPropertyChanged("SPINLOT"); } }
        private string _LMONTH; public string LMONTH { get { return _LMONTH; } set { _LMONTH = value; OnPropertyChanged("LMONTH"); } }
        private string _DATES; public string DATES { get { return _DATES; } set { _DATES = value; OnPropertyChanged("DATES"); } }
        private string _DATET; public string DATET { get { return _DATET; } set { _DATET = value; OnPropertyChanged("DATET"); } }
         
     
        public MainViewModel()
            : base()
        {
            if (SetEnv == null)
            {
                SetEnv = new SETINTEXDB();
            }
            if (SetData == null)
            {
                SetData = new SETINTEXDB();
            }
            if (SetProd == null)
            {
                SetProd = new SETINTEXDB();
            }
            Helper.GetLastMonth(ref _LMONTH, ref _DATES, ref _DATET);
            if (app.User.Trim() == "ITXV")
            {
                _LMONTH = "201501";
            }           
        }
        ~MainViewModel()
        {

        }
       
        public void BuildData(DataRow dwInput)
        {
              try
            {
                INTEXDBC.UpdateICC_PDC(null, 2);//对作业记录进行纱支/白花分组
                INTEXDBC.UpdateICC_PDC(null, 3);
                DataRow dwData = SetEnv.ICC_PDC.NewRow();
                dwData["ABFAGANG"] = dwInput["ABFAGANG"];
                dwData["NEWDATE"] = dwInput["NEWDATE"];
                INTEXDBC.DeleteICC_HRPDC(null, 3);
                INTEXDBC.InsertICC_HRPDC(dwData, 1);
                INTEXDBC.UpdateICC_HRPDC(dwData, 2);
                INTEXDBC.UpdateICC_HRPDC(dwData, 3);
                SetData.Clear();
                DataSet SResult = INTEXDBC.QueryICC_HRPDC(dwData, 2);              
                SetData.Merge(SResult); 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
      
    }
}
